package io.github.talelin.latticy.service;

import io.github.talelin.latticy.entity.Setting;
import io.github.talelin.latticy.repository.SettingRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class SettingService {

    @Autowired
    private SettingRepository settingRepository;

    public Boolean getAudit() {;
        return settingRepository.findAuditVal("audit");
    }

    @Transactional
    public void updateAudit() {
        Setting setting = settingRepository.findByName("audit");
        if (this.getAudit()) {
            setting.setVal("false");
        } else {
            setting.setVal("true");
        }
        settingRepository.save(setting);
    }

}
